<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <link rel="Shortcut Icon" href="../images/aecc.ico" type="image/x-icon" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="../StaticFiles/element-ui/element-ui.css">
  <link rel="stylesheet" href="../StaticFiles/nprogress/nprogress.min.css">
  <link rel="stylesheet" href="../styles/vue-page-common.css">
  <script src="../Scripts/vue.min.js"></script>
  <script src="../StaticFiles/element-ui/element-ui.js"></script>
  <script src="../Scripts/axios.min.js"></script>
  <script src="../StaticFiles/nprogress/nprogress.min.js"></script>
  <script src="../Scripts/crypto-js.js"></script>
  <script src="../Scripts/secret.js"></script>
  <script src="../Scripts/dayjs.min.js"></script>
  <script src="../Scripts/axios.config.js"></script>
  <title>设备排产查询报表</title>
</head>

<body>
  <div id="app" v-cloak v-on:keyup.enter="getData">
    <!-- 报表标题 -->
    <vue2-report-header :title="'设备排产查询报表'"></vue2-report-header>
    <div style="padding: 10px;">
      <!-- 查询条件区 -->
      <el-form :inline="true" :model="queryInfo" ref="queryInfoRef" :label-position="'left'" :rules="rules">
        <el-form-item label="组织结构:" prop="selectOrg">
          <el-cascader :options="orginazition" :props="{ checkStrictly: true}" ref="orginazitionRef"
            v-model="queryInfo.selectOrg" clearable style="width:300px;">
          </el-cascader>
        </el-form-item>

        <el-form-item label="派工完成时间:" prop="plannedfinishdate">
          <el-date-picker v-model="queryInfo.plannedfinishdate" type="daterange" range-separator="至"
            value-format="yyyy-MM-dd" start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions">
          </el-date-picker>
        </el-form-item>

        <el-form-item label="派工开始时间:">
          <el-date-picker v-model="queryInfo.plannedstartdate" type="daterange" range-separator="至"
            value-format="yyyy-MM-dd" start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions">
          </el-date-picker>
        </el-form-item>

        <el-form-item label="设备编号:">
          <el-input v-model.trim="queryInfo.machineno" placeholder="请输入" clearable style="width: 140px;"></el-input>
        </el-form-item>

        <el-form-item label="派工人:">
          <el-input v-model.trim="queryInfo.dispatcher" placeholder="请输入" clearable style="width: 120px;"></el-input>
        </el-form-item>

        <el-form-item label="领工人:">
          <el-input v-model.trim="queryInfo.ligongren" placeholder="请输入" clearable style="width: 100px;"></el-input>
        </el-form-item>

        <el-form-item label="领工时间:">
          <el-date-picker v-model="queryInfo.linggongdate" type="daterange" range-separator="至"
            value-format="yyyy-MM-dd" start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions">
          </el-date-picker>
        </el-form-item>

        <el-form-item label="报工时间:">
          <el-date-picker v-model="queryInfo.reportdate" type="daterange" range-separator="至" value-format="yyyy-MM-dd"
            start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions"></el-date-picker>
        </el-form-item>

        <el-form-item prop='mfgordername' label="订单号:">
          <el-autocomplete v-model.trim="queryInfo.mfgordername" placeholder="请输入订单号" :trigger-on-focus="false"
            style="width:240px;" :fetch-suggestions="searchMfgorderAsync" :value-key="'mfgordername'" :debounce="500">
          </el-autocomplete>
        </el-form-item>

        <el-form-item prop='productname' label="零件图号:">
          <el-autocomplete v-model.trim="queryInfo.productname" placeholder="请输入零件图号" :trigger-on-focus="false"
            style="width:240px;" :fetch-suggestions="searchProductAsync" :value-key="'productname'" :debounce="500">
          </el-autocomplete>
        </el-form-item>

        <el-form-item prop='containername' label="流水卡号:">
          <el-autocomplete v-model.trim="queryInfo.containername" placeholder="请输入流水卡号" :trigger-on-focus="false"
            style="width:240px;" :fetch-suggestions="searchContainerAsync" :value-key="'containername'" :debounce="500">
          </el-autocomplete>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="small" @click="getData">查询</el-button>
          <el-button type="primary" icon="el-icon-download" size="small" @click="getExportExcel">导出</el-button>
        </el-form-item>
      </el-form>

      <!-- 表格显示区 -->
      <el-table v-loading="loading" v-loading.fullscreen.lock="loading" :element-loading-text="loadingText"
        element-loading-background="rgba(0,0,0,0.8)" :data="dataList" stripe border>
        <el-table-column type="index" width="50px"></el-table-column>
        <el-table-column label="设备名称" prop="description" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column label="设备编号" prop="resourcename" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column label="订单号" prop="mfgordername" width="120" show-overflow-tooltip></el-table-column>
        <el-table-column label="流水卡号" prop="containername" show-overflow-tooltip></el-table-column>
        <el-table-column label="工序" prop="workflowstepname" width="140" show-overflow-tooltip></el-table-column>
        <el-table-column label="工区" prop="workcentername" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column label="班组" prop="teamname" width="140" show-overflow-tooltip></el-table-column>
        <el-table-column label="派工人" prop="dispatchemployeename" width="60"></el-table-column>
        <el-table-column label="派工开始时间" prop="plannedstartdate" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column label="派工结束时间" prop="plannedfinishdate" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column label="领工人" prop="recvperson" width="60"></el-table-column>
        <el-table-column label="领工时间" prop="recvdate" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column label="报工时间" prop="reportdate" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column label="超期天数" prop="dalaydays" width="80"></el-table-column>
        <el-table-column label="其他信息" width="80px" type="expand">
          <template slot-scope="props">
            <el-descriptions title="其他信息" :column="4" border>
              <el-descriptions-item>
                <template slot="label">
                  <i class="el-icon-tickets"></i> 批次号
                </template>
                {{props.row.togetherflag}}
              </el-descriptions-item>
              <el-descriptions-item>
                <template slot="label">
                  <i class="el-icon-tickets"></i> 零件图号
                </template>
                {{props.row.productname}}
              </el-descriptions-item>
              <el-descriptions-item>
                <template slot="label">
                  <i class="el-icon-tickets"></i> 零件名称
                </template>
                {{props.row.productdescription}}
              </el-descriptions-item>

            </el-descriptions>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页组件 -->
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
        :current-page="queryInfo.currentPage" :page-sizes="[12,50,100]" :page-size="queryInfo.pageSize"
        layout="prev,pager,next,jumper,sizes,total" :total="total">
      </el-pagination>

      <!-- 回到顶部 -->
      <el-backtop></el-backtop>
    </div>
  </div>

  <script type="module">
    import { getParams, fetchSuggestion, exportExcelData } from '../Scripts/hooks/useCommonMethod.js'
    import { getMESOrginazition } from '../Scripts/hooks/fetchAPI.js'
    import { prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth } from '../Scripts/hooks/useDateShortCut.js'
    import { splitDate } from '../Scripts/hooks/format.js'
    import Vue2ReportHeader from '../Scripts/components/Vue2ReportHeader.js'
    const app = new Vue({
      el: '#app',
      components: { Vue2ReportHeader },
      data: {
        splitDate,
        total: 0,
        loading: false,
        loadingText: '数据加载中...',
        queryInfo: {
          selectOrg: [],// 组织结构
          mfgordername: '',// 订单号
          machineno: '', // 设备编号
          plannedstartdate: '', // 派工开始时间
          plannedfinishdate: '', // 派工结束时间
          dispatcher: '', // 派工人
          linggongdate: '', // 领工时间
          reportdate: '', // 报工时间
          ligongren: '', // 领工人
          productname: '',
          containername: '',
          currentPage: 1,//当前页
          pageSize: 12//每页显示条数
        },
        dataList: [],
        orginazition: [],
        // 表单验证
        rules: {
          selectOrg: [{ required: true, message: '组织结构不能为空', trigger: 'change' }],
          plannedfinishdate: [{ required: true, message: '派工完成时间不能为空', trigger: 'change' }]
        },
        pickerOptions: { shortcuts: [prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth] }
      },
      methods: {
        // 查询订单号
        searchMfgorderAsync(value, callback) {
          fetchSuggestion({ actionName: 'getMfgordernameAsync', name: 'mfgordername', value, callback });
        },
        // 查询件号
        searchProductAsync(value, callback) {
          fetchSuggestion({ actionName: 'getProductnameAsync', name: 'productname', value, callback });
        },
        // 查询批次号
        searchContainerAsync(value, callback) {
          fetchSuggestion({ actionName: 'getContainernameAsync', name: 'containername', value, callback });
        },
        //查询数据
        async getData() {
          this.$refs['queryInfoRef'].validate(async (valid) => {
            if (!valid) {
              return this.$message.error('必填项不能为空');
            } else {
              this.loading = true;
              this.loadingText = '数据加载中...';
              const { data: { data, meta, total } } = await axios.post('../handler/report/MachineTaskPlanReport.ashx?action=getData', {
                type: 'getData',
                ...this.queryInfo
              })
              this.loading = false;
              if (meta.status === 500) { return this.$message.error(meta.msg); }
              this.dataList = data;
              this.total = total;
            }
          })
        },
        //导出excel
        async getExportExcel() {
          this.$refs['queryInfoRef'].validate(async (valid) => {
            if (!valid) {
              return this.$message.error('必填项不能为空');
            } else {
              const config = {
                url: '../handler/report/MachineTaskPlanReport.ashx?action=exportExcel',
                data: { type: 'exportExcel', ...this.queryInfo }
              }
              exportExcelData(config, this);
            }
          })
        },
        handleCurrentChange(newPage) {
          this.queryInfo.currentPage = newPage;
          this.getData();
        },
        handleSizeChange(newSize) {
          this.queryInfo.pageSize = newSize;
          this.getData();
        }
      },
      async mounted() {
        const monday = dayjs().startOf('week').add(1, 'day').format('YYYY-MM-DD');
        const sunday = dayjs().endOf('week').add(1, 'day').format('YYYY-MM-DD');
        this.queryInfo.plannedfinishdate = [monday, sunday];
        const factoryid = Decrypt(getParams('factoryid'));
        this.queryInfo.selectOrg = [factoryid];
        this.orginazition = await getMESOrginazition({ factoryCode: '600|601|602|604|607|608|609' });
      },
      watch: {
        queryInfo: { handler() { this.queryInfo.currentPage = 1 }, deep: true }
      }
    })
  </script>
</body>

</html>